{% from "v2ex/macros.html" import list_comment with context %}

{% extends "v2ex/_base.html" %}
{% block title %}{{ data.title }}{% endblock %}
{% block rightbar %}{% endblock %}
{% block body %}
<div class="sep20"></div>
<div class="box">
    <div class="header">
        <div class="fr">
            <img alt="image" class="img-circle" src="/static/img/avatar.jpg">
        </div>
        <a href="/">SJZLUG</a>
        <span class="chevron">&nbsp;›&nbsp;</span>
        <a href="/subcate/{{data.post.subcateid}}">{{data.post.subcateid}}</a>
        <div class="sep10"></div>
        <h1>{{data.post.title}}</h1>
        <div id="topic_419078_votes" class="votes">
            <span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;&nbsp; &nbsp;&nbsp;
            <span class="glyphicon glyphicon-thumbs-down"></span>
        </div>
        <small class="gray">
            &nbsp; · &nbsp;<a href="/user/{{data.post.authorid}}">{{data.post.authorid}}</a> · 1 天前 发布 · {{data.post.comments}} 次点击 &nbsp;
        </small>
    </div>
    <div class="cell">
        <div class="topic_content">
            {{data.post.content_html|safe}}
        </div>
    </div>
    <div class="topic_buttons">
        <div class="fr gray f11" style="line-height: 12px; padding-top: 3px; text-shadow: 0px 1px 0px #fff;">{{data.post.comments}} 次点击 &nbsp;∙&nbsp; 4 人收藏 &nbsp; ∙&nbsp; 2 人感谢 &nbsp; </div>
        <a href="#" class="tb">加入收藏</a> &nbsp;&nbsp;&nbsp;
    </div>
</div>
{% if data.post.commentlist %}
<div class="sep20"></div>
<div class="box">
    <div class="cell">
        <div class="fr" style="margin: -3px -5px 0px 0px;">
            <a href="/tag/tagid" class="tag"> 标签</a>
        </div>
        <span class="gray">{{ data.post.comments }} 回复 &nbsp;<strong class="snow">|</strong> &nbsp;直到 {{ data.post.last_comment_time }}</span>
    </div>
    <div class="cell">
        pages is here
    </div>
    {{ list_comment(data.post.commentlist) }}
</div>
{% endif %}
{% if data.curr_user.is_active %}
<div class="sep20"></div>
<div class="box">
    <div class="cell">
        <div class="fr"><a href="#" onclick="goTop()"><span class="glyphicon glyphicon-eject"></span> 回到顶部</a></div>
        添加一条新回复
    </div>
    <div class="cell">
        <div style="display:none;">
        <form id = "commentform" method="post" action="/postcomment">
            {{data.form.hidden_tag()}}
            {{ data.form.post_id(placeholder="post_id",class="form-control") }}
            {{ data.form.content_html(placeholder="comment content",class="form-control") }}
        </form>
        </div>
        <div id="test-editormd" style="margin-bottom:0px;">
            <textarea style="display:none;"></textarea>
        </div>
        <div class="sep10"></div>
        <div class="fr">
            <div class="sep5"></div>
            <span class="gray">请尽量让自己的回复能够对别人有帮助</span>
        </div>
        <button  id = "btn_send" class="super normal button"><span class="glyphicon glyphicon-send"></span>&nbsp;&nbsp; 回复</button>
        </form>
    </div>
    <div class="inner">
        <div class="fr"><a href="/"><span class="glyphicon glyphicon-arrow-left"></span> SJZLUG</a></div>
        &nbsp;
    </div>
</div>
{% endif %}
<div class="sep20"></div>
<link rel="stylesheet" type="text/css" media="screen" href="/static/v2ex/js/plugs/editor.md/editormd.min.css" />
<script src="/static/v2ex/js/plugs/editor.md/editormd.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var testEditor;
    $(function() {
        testEditor = editormd("test-editormd", {
            width   : "100%",
            height  : 120,
            toolbar : false,
            watch   : false,
            saveHTMLToTextarea : true,
            syncScrolling : false,
            path    : "/static/v2ex/js/plugs/editor.md/lib/"
        });
    });

    $('#btn_send').click(function(){
        $("#btn_send").attr('disabled',true);
        var form= document.getElementById("commentform");
        if (form){
            form.post_id.value = $("#post_id")[0].value;
            testEditor.previewing();
            testEditor.previewing();
            form.content_html.value = testEditor.getHTML();
            form.action="/post/" + form.post_id.value;
            form.submit();
        }
        $("#btn_send").attr('disabled',false);
    });

    $('#btn_watch').click(function(){
        testEditor.previewing();
        return false;
    });

});
</script>
{% endblock %}
